<?php

  class ArticleAction extends CommonAction{

  	

  	function  index(){



	                    $data = D("Article");

						import('ORG.Util.Page');

					 $count=$data->count();// 查询总数据记录

					 $Page = new Page($count,C('PAGESIZE'));

					 $show= $Page->show();

	                    $list = $data->relation(true)->order("createtime DESC")->limit($Page->firstRow.','.$Page->listRows)->select();

	                    

	                      $this->assign("list",$list);

						  $this->assign("page",$show);

                          $this->display();


       }

       

       

       function add(){

   	  	
   	  	if(isset($_POST['submit'])){
   	  	       $data = $_POST;
           $data['createtime']=mktime();
           $data['status']= 1 ;
   	  	    if(M('Article')->add($data)){
   	  	    	$this->success("添加文章成功！",U('index'));
   	  	    }else{
   	  	    	
   	  	    	$this->error("添加文章失败");
   	  	    }
   	  	}else{
   	  		$this->list =M('Category')->select();
   	  		$this->display();
   	  	}
       	
       }


  	

  	   /**

  	    * 

  	    * 编辑文章

  	    */

    	function  edit(){
	              $id= htmlspecialchars($_GET['id']);
	              if(is_numeric($id)){
	              	  if(isset($_POST['submit'])){
	              	  	  $data = $_POST;
	              	  	  $data['createtime']=mktime();
	              	  	  M('Article')->where("id=".$id)->save($data);
	              	  	  $this->success("更新成功！",U('index'));
	              	  }else{
	              	  	$this->list =M('Category')->select();
	              	  	$this->li =M('Article')->where("id=".$id)->find();
	              	  	$this->display();
	              	  }
	              	
	              }
    		
  		

  	 }

  	 

  	 /**

  	  * 删除文章

  	  * 

  	  */

  	 function del(){


	                $qstr = $_GET['qstr'];

  		  					   $data=M("Article");  		  

			if(isset($qstr)){

			   $arr=explode(",",$qstr);



			   foreach($arr as $val){

			     $data->where("id=$val")->delete();

			       

			   }

			   $this->success("删除成功！",__URL__."/index");

			

			}else{

			

			  if(isset($_GET['id'])){

			  $data->where("id=".$_GET['id'])->delete();

			   $this->success("删除成功！",__URL__."/index");

			  }else{

			  

			   $this->error("请选择要删除的ID");

			  }

			}

	                    

  	 }

	 



  }

?>